package com.xly.util;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * 高频方法集合类
 */
public class ToolUtil {

    //处理导出文件中文乱码问题，兼容常用浏览器
    public static String getExcelTitle(HttpServletRequest request,String fileName){
        final String userAgent = request.getHeader("USER-AGENT");
        try {
            if (userAgent != null && userAgent.indexOf("Firefox") >= 0 || userAgent.indexOf("Chrome") >= 0
                    || userAgent.indexOf("Safari") >= 0) {
                    fileName= new String((fileName).getBytes(), "ISO8859-1");
            } else {
                fileName=URLEncoder.encode(fileName,"UTF8"); //其他浏览器
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return  fileName;
    }
}